<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<style type="text/css">
			.form-box{
				text-align: center;
				margin-top: 20px;
			}
		</style>
	</head>
	</style>
	<body style="padding: 0px;">
		<div class="easyui-layout" style="width:100%;height:500px;">
			<div data-options="region:'center'">
				<div>
					<table id="dg" style="width: 100%;" class="table_style">
					</table>
				</div>
			</div>
		</div>
		<div id="toolbar"></div>
		<div id="dlg" closed="true" class="easyui-dialog" style="width: 400px;height: 200px;" title="Basic Dialog">
			<div class="form-box">
				<form id="ff" method="post">
					<table class="displaytable">
						<tr style="display: none;">
							<td width="40%">ID：</td>
							<td width="60%">
								<input type="text" class="easyui-textbox" id="INPUT_ID" name="ID" style="width: 80%;"/>
							</td>
						</tr>
						<tr>
							<td width="40%">用户组名称：</td>
							<td width="60%">
								<input type="text" class="easyui-textbox" id="INPUT_CUSTOMER_TYPE" name="CUSTOMER_TYPE" style="width: 80%;" required/>
							</td>
						</tr>
						<tr>
							<td width="40%">用户组类型：</td>
							<td width="60%">
								<input type="text" class="easyui-combobox" id="INPUT_PROPERTY" name="PROPERTY" style="width: 80%;" required/>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/json2.js"></script>
	<script type="text/javascript" src="../../../JS/buildDialogSearch.js" ></script>
	<script type="text/javascript">
		var toolbartype = TOOLBAR_ADD + TOOLBAR_DELETE + TOOLBAR_EDITOR;
		var toolbarLIst = AddToolBar(toolbartype);
		$("#toolbar").append(toolbarLIst);
		getDataGrid();
		
		$('#INPUT_PROPERTY').combobox({
			panelHeight: "50px",
			valueField:'id',
    		textField:'text',
    		data:[{
    			id:'0',
    			text:'实时定价'
    		},{
    			id:'1',
    			text:'后定价'
    		}]
		})
	
		function getDataGrid(){
			$("#dg").datagrid({
				url: RemoteLinkAddress + '/logistics/customertype/listall.do',
				toolbar: '#toolbar',
				method: 'get',
				pagination: 'true',
				rownumbers: 'true',
				fitColumns: 'false',
				singleSelect: 'true',
				height:'450',
				columns: [
					[{
						field: 'ID',
						title: 'ID',
						width: '0%'
					}, {
						field: 'CUSTOMER_TYPE',
						title: '用户组',
						width: '24%',
						align: 'center'
					}, {
						field: 'CREATE_TIME',
						title: '创建时间',
						width: '24%',
						align: 'center'
					}, {
						field: 'CREATE_MAN',
						title: '创建人',
						width: '24%',
						align: 'center'
					}, {
						field: 'PROPERTY',
						title: '用户组类型',
						width: '24%',
						align: 'center',
						formatter: function(value, row, index) {
							if(value === '0'){
								return '实时定价';
							}else if(value === '1'){
								return '后定价';
							}
						}
					}, ]
				],
				onDblClickRow: function(index, row) {
					openDialog(row.ID, '修改');
				}
			});
			$('#dg').datagrid('hideColumn', 'ID'); //隐藏第一列
		}
		
		//打开dialog
		function openDialog(id, title){
			$('#ff').form('clear');
			$("#dlg").dialog({
				title:title,
				width:'400',
				height:'200',
				toolbar:[{
					text:'保存',
					iconCls:'icon-save',
					handler:function(){
						saveData();
					}
				},{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteData();
					}
				},{
					text:'取消',
					iconCls:'icon-cancel',
					handler:function(){
						$("#dlg").dialog('close');
					}
				}]
			});
			if(id !== ''){
				$('#ff').form('load', RemoteLinkAddress + '/logistics/customertype/findbyid.do?ID=' + id);
			}
			$('#dlg').dialog('open').dialog('center');
		}
		
		function newdata(){
			openDialog('', '新增');
		}
		
		function editdata (){
			var row = $('#dg').datagrid('getSelected');
			if(!row) {
				$.messager.alert('Info', "请选择你需要修改的数据"); /*判断是否有行被选中，如果没有，则弹出警告框，提示用户修改数据*/
				return;
			}
			openDialog(row.ID, '修改');
		}
		
		function destroy (){
			var row = $('#dg').datagrid('getSelected');
			if(!row) {
				$.messager.alert('Info', "请选择你需要删除的数据"); /*判断是否有行被选中，如果没有，则弹出警告框，提示用户修改数据*/
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + '/logistics/customertype/delete.do',{
						ID:row.ID
					}, function(result){
						if(result.msg === 'success'){
							$.messager.alert('提示信息', '删除成功!');
							$('#dg').datagrid('reload');
						}else{
							$.messager.alert('提示信息', '删除失败!');
						}
					},'json')
				}
			});
			
		}
		
		function saveData(){
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			if($('#INPUT_ID').textbox('getValue') === ''){
				submitData(RemoteLinkAddress + '/logistics/customertype/save.do');
			}else {
				submitData(RemoteLinkAddress + '/logistics/customertype/update.do');
			}
		}
		
		function deleteData(){
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + '/logistics/customertype/delete.do',{
						ID:$('#INPUT_ID').textbox('getValue')
					}, function(result){
						if(result.msg === 'success'){
							$.messager.alert('提示信息', '删除成功!');
							$('#dlg').dialog('close');
							$('#dg').datagrid('reload');
						}else{
							$.messager.alert('提示信息', '删除失败!');
						}
					},'json')
				}
			});
		}
		
		function submitData(_url){
			var id = $('#INPUT_ID').textbox('getValue');
			var customer_type = $('#INPUT_CUSTOMER_TYPE').textbox('getValue');
			var property = $('#INPUT_PROPERTY').combobox('getValue');
			var parameter = new Object();
			if(id !== ''){
				parameter.ID = id;
			}
			parameter.CUSTOMER_TYPE = customer_type;
			parameter.PROPERTY = property;
			$.ajax({
				type:"post",
				url:_url,
				dataType: "JSON",
				data:parameter,
				success:function(result){
					if(result.msg === 'success'){
						$("#dlg").dialog('close');
						$('#dg').datagrid('reload');
						$.messager.alert('提示信息', '保存成功!');
					}
				},
				error:function(result){
					
				}
			});
		}
		
	</script>

</html>